home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 April / PCWorld_2008-04_cd.bin / komercni software / miton / SystemMechanic7Pro.exe / {app} / smhtml.dll / 1033 / HTML / TABLE.JS < prev    next >
Text File  |  2008-01-24  |  6KB  |  218 lines

  1.  
  2. //This is an upgrade version of DataTable class
  3.  
  4.  
  5. //***************** Object Class *******************************//
  6. function Object(id)
  7. {
  8.   this.ID= id || "";
  9.   this.Class = "";
  10.   this.Style = "";
  11.   this.Width = "";
  12.   this.Data = "";
  13.   this.Align = "";
  14.   this.Name = "Object";
  15. }
  16. //***************** End  Object Class *******************************//
  17.  
  18.  
  19. //***************** TD Class *******************************//
  20. function TD(id)
  21. {
  22.   this.base = Object;
  23.   this.base(id || "");
  24.   this.Render = __TDRender;
  25.   
  26.   function __TDRender()
  27.   {
  28.     var content = "";
  29.     content += "<td  class=\""+ this.Class +"\" ";
  30.     if (this.ID != "")
  31.        content += " id=\"" + this.ID + "\"";
  32.     if (this.Width != "")
  33.        content += " width=\"" + this.Width + "\"";
  34.     if (this.Align != "")
  35.        content += " align=\"" + this.Align + "\"";
  36.     content += ">\n";
  37.     content += this.Data;
  38.     content += "\n</td>\n";
  39.     return content;
  40.   }
  41.   //inherit from object
  42.   TD.prototype = new Object;
  43. }
  44.  
  45. //***************** End TD Class *******************************//
  46.  
  47.  
  48. //***************** TR Class *******************************//
  49. function TR(id)
  50. {
  51.   this.base = Object;
  52.   this.base(id || "");
  53.   this.TDs = new Array();
  54.   this.Add = __TRAdd;
  55.   this.Render = __TRRender;
  56.   
  57.   function __TRAdd(ObjectTD)
  58.   {
  59.     this.TDs[this.TDs.length] = ObjectTD;
  60.   }
  61.   
  62.   function __TRRender(RowClass)
  63.   {
  64.     var rowClass = RowClass || this.Class;
  65.     var content = "";
  66.     content += "\n<tr valign=\"top\"  id='"+ this.ID  +"' class=\""+ rowClass +"\">\n";
  67.     
  68.     for ( x = 0; x < this.TDs.length; x++)
  69.       content += this.TDs[x].Render();
  70.       
  71.     content += "\n</tr>\n";
  72.     return content;
  73.   }
  74.   //inherit from object
  75.   TR.prototype = new Object;
  76. }
  77.  
  78. //***************** End TR Class *******************************//
  79.  
  80. //***************** Table Class *******************************//
  81.  
  82. function Table(id)
  83. {
  84.   this.base = Object;
  85.   this.base(id);
  86.   this.ItemClass = "i";
  87.   this.AlternateItemClass = "a";
  88.   this.Border = "0";
  89.   this.Cellspacing = "0";
  90.   this.Cellpadding = "0";
  91.   this.TRs = new Array();
  92.  
  93.   this.Add = __TableAdd;
  94.   this.Render = __TableRender;
  95.   this.Alternate = __TableRowAlternate;
  96.   this.IsRendered = __TableIsRendered;
  97.   this.ChangeClassInRowByIndex = __ChangeClassInRowByIndex;
  98.   
  99.   this._ClientID = __ClientID;
  100.   
  101.   //inherit from object
  102.   Table.prototype = new Object;
  103.   
  104.   function __TableIsRendered()
  105.   {
  106.     return (Get(this._ClientID()) != null);
  107.   }
  108.   
  109.   function __ClientID()
  110.   {
  111.     return "datatable_tbl_" + this.ID;
  112.   }
  113.   
  114.     
  115.   function __TableAdd(ObjectTR)
  116.   {
  117.     this.TRs[this.TRs.length] = ObjectTR;
  118.     
  119.     var tbl = Get("datatable_tbl_" + this.ID);
  120.     if (tbl != null)
  121.     {
  122.       // The data table has already been rendered, so we need to manually 
  123.       // add the data table item.
  124.       var tbody ;      
  125.       var row ;
  126.       tbody = tbl.childNodes[0];
  127.       if(tbody.rows)
  128.          row = tbody.insertRow(tbody.rows.length); //ie
  129.       else
  130.          row = tbl.insertRow(tbl.childNodes.length ); //firefox
  131.      
  132.       // adding the primary key to the table row 'id' 
  133.       if(ObjectTR.ID != "")    row.setAttribute('id', ObjectTR.ID  );
  134.       if (ObjectTR.Class != "") row.className = ObjectTR.Class;
  135.       
  136.       
  137.        var cell = null;
  138.        for (var x = 0; x < ObjectTR.TDs.length; x++)
  139.       {
  140.        cell = row.insertCell(row.cells.length);
  141.        if (ObjectTR.TDs[x].ID != "") cell.setAttribute("id", ObjectTR.TDs[x].ID);
  142.        if (ObjectTR.TDs[x].Align != "") cell.setAttribute("align", ObjectTR.TDs[x].Align);
  143.        if (ObjectTR.TDs[x].Width != "") cell.setAttribute("width", ObjectTR.TDs[x].Width);
  144.        if (ObjectTR.TDs[x].Class != "") cell.className = ObjectTR.TDs[x].Class;
  145.        cell.innerHTML = ObjectTR.TDs[x].Data;
  146.       }
  147.       //recalculate row background colours
  148.       this.Alternate(tbl);
  149.     }//null if
  150.   }
  151.   
  152.   function __TableRender()
  153.   {
  154.      var content = "";
  155.      content += "\n<table id=\"datatable_tbl_" + this.ID + "\" cellspacing=\"" + this.Cellspacing + "\" cellpadding=\"" + this.Cellpadding + "\" border=\"" + this.Border + "\"";
  156.      if (this.Width != "")
  157.        content += " width=\"" + this.Width + "\"";
  158.      if (this.Class != "")
  159.        content += " class=\"" + this.Class + "\"";
  160.      content += ">\n";
  161.   
  162.      for (var x = 0; x < this.TRs.length; x++)
  163.      {
  164.        if((this.ItemClass != "") && (this.AlternateItemClass != ""))
  165.        {
  166.         var rowClass = this.ItemClass;
  167.         if(x % 2 != 0)
  168.           rowClass = this.AlternateItemClass;
  169.           
  170.          content += this.TRs[x].Render(rowClass);
  171.        }else
  172.        {
  173.          if(this.ItemClass != "")
  174.            content += this.TRs[x].Render(this.ItemClass);
  175.          else
  176.            content += this.TRs[x].Render();
  177.        } 
  178.      }
  179.      content += "</table>";
  180.      return content;
  181.   }
  182.   
  183.   function __ChangeClassInRowByIndex(index, Class)
  184.   {
  185.     var element = Get("datatable_tbl_" + this.ID);
  186.     if(element == null)
  187.     return;
  188.     try
  189.     {
  190.     var tbody = element.childNodes[0];
  191.     var row = tbody.rows[index];
  192.     row.className = Class;
  193.     }catch(e){}
  194.   }
  195.   
  196.     
  197.   function __TableRowAlternate(objTable)
  198.   {
  199.     if (this.ItemClass == "" )   return;
  200.     if (this.AlternateItemClass == "" )  this.AlternateItemClass = this.ItemClass;
  201.     var table =  objTable || Get("datatable_tbl_" + this.ID);  
  202.     if (table == null )   return;
  203.     var rows = table.rows; 
  204.     for(i = 0; i < rows.length; i++)
  205.     {          
  206.       if(i % 2 == 0)
  207.          rows[i].className = this.ItemClass;
  208.       else
  209.          rows[i].className = this.AlternateItemClass;
  210.     } 
  211.   }
  212.   
  213. }
  214.  
  215. //***************** End Table Class *******************************//
  216.  
  217.  
  218.